import { createRouter, createWebHistory } from 'vue-router';

import Archives from '@/views/archives/index.vue';
import Home from '@/views/home/index.vue';
import UtilsAnimate from '@/views/utils-animate/index.vue';

const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_APP_ROOT),
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home,
      meta: {
        title: '示例',
      },
    },
    {
      path: '/archives',
      name: 'Archives',
      component: Archives,
      meta: {
        title: '示例',
      },
    },
    {
      path: '/utils',
      name: 'UtilsAnimate',
      component: UtilsAnimate,
      meta: {
        title: '示例',
      },
    },
  ],
});

router.afterEach((to) => {
  const baseTitle = import.meta.env.VITE_APP_NAME_ZH;
  window.document.title = to.meta.title ? `${to.meta.title} | ${baseTitle}` : baseTitle;
});

export default router;
